package core

import (
	"fmt"
	sqladapter "github.com/Blank-Xu/sql-adapter"
	"github.com/casbin/casbin/v2"
	"github.com/wdaglb/korm"
)

var (
	Enforcer *casbin.Enforcer
)

func InitCasbin() {
	ctx := korm.NewContext()
	a, err := sqladapter.NewAdapter(ctx.Db().Handler(), "mysql", "casbin")
	if err != nil {
		panic(err)
	}
	Enforcer, err = casbin.NewEnforcer("./data/rbac_model.conf", a)
	if err != nil {
		panic(err)
	}
	fmt.Printf("casbin init success\n")
	//if err = e.LoadPolicy(); err != nil {
	//	panic(err)
	//}
	//
	//fmt.Println("load policy success")
}
